<!DOCTYPE html>
<html lang="zh-CN">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="机器学习，深度学习，强化学习，算法，Linux">
  <meta name="author" content="seven">
  <meta name="keywords" content="">
  <title>机器学习之线性回归python实现 - SimpleAI</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />
<link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_fmb4a04yx8h.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">




<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


<meta name="generator" content="Hexo 4.2.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>Simple AI</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/">
              <i class="iconfont icon-home-fill"></i>
              首页</a>
          </li>
        
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/archives/">
              <i class="iconfont icon-archive-fill"></i>
              归档</a>
          </li>
        
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/categories/">
              <i class="iconfont icon-category-fill"></i>
              分类</a>
          </li>
        
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/tags/">
              <i class="iconfont icon-tags-fill"></i>
              标签</a>
          </li>
        
          
          
          
          <li class="nav-item">
            <a class="nav-link" href="/about/">
              <i class="iconfont icon-user-fill"></i>
              关于</a>
          </li>
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('https://eveseven.oss-cn-shanghai.aliyuncs.com/20200530224522.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
                <div class="mt-3 post-meta">
                  <i class="iconfont icon-date-fill" aria-hidden="true"></i>
                  <time datetime="2018-07-21 10:00">
                    2018年7月21日 上午
                  </time>
                </div>
              

              <div class="mt-1">
                
                  
                  <span class="post-meta mr-2">
                    <i class="iconfont icon-chart"></i>
                    1.2k 字
                  </span>
                

                
                  
                  <span class="post-meta mr-2">
                      <i class="iconfont icon-clock-fill"></i>
                    
                    
                    16
                     分钟
                  </span>
                

                
                  <!-- 不蒜子统计文章PV -->
                  
                  <span id="busuanzi_container_page_pv" class="post-meta" style="display: none">
                    <i class="iconfont icon-eye" aria-hidden="true"></i>
                    <span id="busuanzi_value_page_pv"></span> 次
                  </span>
                
              </div>
            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
              <p class="note note-info">
                
                  本文最后更新于：2 小时前
                
              </p>
            
            <article class="markdown-body">
              <h2 id="首先导入所需要的库文件"><a href="#首先导入所需要的库文件" class="headerlink" title="首先导入所需要的库文件"></a>首先导入所需要的库文件</h2><div class="hljs"><pre><code class="hljs python"><span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt  <span class="hljs-comment"># 导入可视化库</span>
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np               <span class="hljs-comment"># 导入数据处理库</span>
<span class="hljs-keyword">from</span> sklearn <span class="hljs-keyword">import</span> datasets     <span class="hljs-comment"># 导入sklearn自带的数据集</span></code></pre></div>

<h2 id="把我们的参数值求解公式-theta-X-TX-1-X-TY-转换为代码"><a href="#把我们的参数值求解公式-theta-X-TX-1-X-TY-转换为代码" class="headerlink" title="把我们的参数值求解公式$\theta=(X^TX)^{-1}X^TY$转换为代码"></a>把我们的参数值求解公式$\theta=(X^TX)^{-1}X^TY$转换为代码</h2><div class="hljs"><pre><code class="hljs python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">fit</span><span class="hljs-params">(self, X, y)</span>:</span>                    <span class="hljs-comment"># 训练集的拟合</span>
        X = np.insert(X, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, axis=<span class="hljs-number">1</span>)  <span class="hljs-comment"># 增加一个维度</span>
        <span class="hljs-keyword">print</span> (X.shape)        
        X_ = np.linalg.inv(X.T.dot(X))  <span class="hljs-comment"># 公式求解 -- X.T表示转置，X.dot(Y)表示矩阵相乘</span>
        self.w = X_.dot(X.T).dot(y)     <span class="hljs-comment"># 返回theta的值</span></code></pre></div>

<h1 id="其中：-X-TX-1-表示为："><a href="#其中：-X-TX-1-表示为：" class="headerlink" title="其中：$(X^TX)^{-1} $表示为："></a>其中：$(X^TX)^{-1} $表示为：</h1><div class="hljs"><pre><code class="hljs python">X_ = np.linalg.inv(X.T.dot(X))  <span class="hljs-comment"># 公式求解 -- X.T表示转置，X.dot(Y)表示矩阵相乘</span>
 np.linalg.inv() 表示求逆矩阵</code></pre></div>

<h1 id="其中：-X-TY-表示为："><a href="#其中：-X-TY-表示为：" class="headerlink" title="其中：$X^TY $表示为："></a>其中：$X^TY $表示为：</h1><div class="hljs"><pre><code class="hljs python">X.T.dot(X)</code></pre></div>

<h1 id="所以完整公式-theta-X-TX-1-X-TY-表示为："><a href="#所以完整公式-theta-X-TX-1-X-TY-表示为：" class="headerlink" title="所以完整公式$\theta=(X^TX)^{-1}X^TY$表示为："></a>所以完整公式$\theta=(X^TX)^{-1}X^TY$表示为：</h1><div class="hljs"><pre><code class="hljs python">X_.dot(X.T).dot(y)</code></pre></div>

<h2 id="由于我们最终得到的线性回归函数是-y-theta-x-b-即预测函数："><a href="#由于我们最终得到的线性回归函数是-y-theta-x-b-即预测函数：" class="headerlink" title="由于我们最终得到的线性回归函数是$y=\theta x+b$即预测函数："></a>由于我们最终得到的线性回归函数是$y=\theta x+b$即预测函数：</h2><div class="hljs"><pre><code class="hljs python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">predict</span><span class="hljs-params">(self, X)</span>:</span>               <span class="hljs-comment"># 测试集的测试反馈</span>
                                    <span class="hljs-comment"># 为偏置权值插入常数项</span>
    X = np.insert(X, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, axis=<span class="hljs-number">1</span>)  <span class="hljs-comment"># 增加一个维度</span>
    y_pred = X.dot(self.w)          <span class="hljs-comment"># 测试集与拟合的训练集相乘</span>
    <span class="hljs-keyword">return</span> y_pred                   <span class="hljs-comment"># 返回最终的预测值</span></code></pre></div>

<h2 id="其中得到的预测结果y-pred-X-text-cdot-theta"><a href="#其中得到的预测结果y-pred-X-text-cdot-theta" class="headerlink" title="其中得到的预测结果y_pred=X_text$\cdot\theta$"></a>其中得到的预测结果y_pred=X_text$\cdot\theta$</h2><div class="hljs"><pre><code class="hljs python">y_pred = X.dot(self.w)          <span class="hljs-comment"># 测试集与参数值相乘</span></code></pre></div>

<h2 id="最终得出线性回归代码："><a href="#最终得出线性回归代码：" class="headerlink" title="最终得出线性回归代码："></a>最终得出线性回归代码：</h2><div class="hljs"><pre><code class="hljs python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LinearRegression</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self)</span>:</span>          <span class="hljs-comment"># 新建变量</span>
        self.w = <span class="hljs-literal">None</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">fit</span><span class="hljs-params">(self, X, y)</span>:</span>         <span class="hljs-comment"># 训练集的拟合</span>
        X = np.insert(X, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, axis=<span class="hljs-number">1</span>)  <span class="hljs-comment"># 增加一个维度</span>
        <span class="hljs-keyword">print</span> (X.shape)        
        X_ = np.linalg.inv(X.T.dot(X))  <span class="hljs-comment"># 公式求解 -- X.T表示转置，X.dot(Y)表示矩阵相乘</span>
        self.w = X_.dot(X.T).dot(y)     <span class="hljs-comment"># 返回theta的值</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">predict</span><span class="hljs-params">(self, X)</span>:</span>               <span class="hljs-comment"># 测试集的测试反馈</span>
                                        <span class="hljs-comment"># 为偏置权值插入常数项</span>
        X = np.insert(X, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, axis=<span class="hljs-number">1</span>)  <span class="hljs-comment"># 增加一个维度</span>
        y_pred = X.dot(self.w)          <span class="hljs-comment"># 测试集与拟合的训练集相乘</span>
        <span class="hljs-keyword">return</span> y_pred                   <span class="hljs-comment"># 返回最终的预测值</span></code></pre></div>

<h2 id="同时我们需要得出预测值与真实值的一个平方平均值"><a href="#同时我们需要得出预测值与真实值的一个平方平均值" class="headerlink" title="同时我们需要得出预测值与真实值的一个平方平均值"></a>同时我们需要得出预测值与真实值的一个平方平均值</h2><div class="hljs"><pre><code class="hljs python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">mean_squared_error</span><span class="hljs-params">(y_true, y_pred)</span>:</span>
                                        <span class="hljs-comment">#真实数据与预测数据之间的差值（平方平均）</span>
    mse = np.mean(np.power(y_true - y_pred, <span class="hljs-number">2</span>))
    <span class="hljs-keyword">return</span> mse</code></pre></div>

<h2 id="最后就是进行我数据的加载，训练，测试过程以及可视化"><a href="#最后就是进行我数据的加载，训练，测试过程以及可视化" class="headerlink" title="最后就是进行我数据的加载，训练，测试过程以及可视化"></a>最后就是进行我数据的加载，训练，测试过程以及可视化</h2><div class="hljs"><pre><code class="hljs python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-comment"># 第一步：导入数据</span>
    <span class="hljs-comment"># 加载糖尿病数据集</span>
    
    diabetes = datasets.load_diabetes()
    <span class="hljs-comment"># 只使用其中一个特征值</span>
    X = diabetes.data[:, np.newaxis, <span class="hljs-number">2</span>]
    <span class="hljs-keyword">print</span> (X.shape)

    <span class="hljs-comment">#第二步：将数据分为训练集以及测试集</span>
    x_train, x_test = X[:<span class="hljs-number">-20</span>], X[<span class="hljs-number">-20</span>:]
    y_train, y_test = diabetes.target[:<span class="hljs-number">-20</span>], diabetes.target[<span class="hljs-number">-20</span>:]

    <span class="hljs-comment">#第三步：导入线性回归类（之前定义的）</span>
    clf = LinearRegression()
    clf.fit(x_train, y_train)    <span class="hljs-comment"># 训练</span>
    y_pred = clf.predict(x_test) <span class="hljs-comment"># 测试</span>

    <span class="hljs-comment">#第四步：测试误差计算（需要引入一个函数）</span>
    <span class="hljs-comment"># 打印平均值平方误差</span>
    <span class="hljs-keyword">print</span> (<span class="hljs-string">"Mean Squared Error:"</span>, mean_squared_error(y_test, y_pred))

    <span class="hljs-comment">#matplotlib可视化输出</span>
    <span class="hljs-comment"># Plot the results</span>
    plt.scatter(x_test[:,<span class="hljs-number">0</span>], y_test,  color=<span class="hljs-string">'black'</span>)         <span class="hljs-comment"># 散点输出</span>
    plt.plot(x_test[:,<span class="hljs-number">0</span>], y_pred, color=<span class="hljs-string">'blue'</span>, linewidth=<span class="hljs-number">3</span>) <span class="hljs-comment"># 预测输出</span>
    plt.show()</code></pre></div>

<h2 id="可视化结果"><a href="#可视化结果" class="headerlink" title="可视化结果"></a>可视化结果</h2><p><img src="https://eveseven.oss-cn-shanghai.aliyuncs.com/20200530225637.png" srcset="/img/loading.gif" alt="image"></p>
<h2 id="完整线性回归的代码"><a href="#完整线性回归的代码" class="headerlink" title="完整线性回归的代码"></a>完整线性回归的代码</h2><div class="hljs"><pre><code class="hljs python"><span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt  <span class="hljs-comment"># 导入可视化库</span>
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np               <span class="hljs-comment"># 导入数据处理库</span>
<span class="hljs-keyword">from</span> sklearn <span class="hljs-keyword">import</span> datasets     <span class="hljs-comment"># 导入sklearn自带的数据集</span>
<span class="hljs-keyword">import</span> csv

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LinearRegression</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self)</span>:</span>          <span class="hljs-comment"># 新建变量</span>
        self.w = <span class="hljs-literal">None</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">fit</span><span class="hljs-params">(self, X, y)</span>:</span>         <span class="hljs-comment"># 训练集的拟合</span>
        X = np.insert(X, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, axis=<span class="hljs-number">1</span>)  <span class="hljs-comment"># 增加一个维度</span>
        <span class="hljs-keyword">print</span> (X.shape)        
        X_ = np.linalg.inv(X.T.dot(X))  <span class="hljs-comment"># 公式求解 -- X.T表示转置，X.dot(Y)表示矩阵相乘</span>
        self.w = X_.dot(X.T).dot(y)     <span class="hljs-comment"># 返回theta的值</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">predict</span><span class="hljs-params">(self, X)</span>:</span>               <span class="hljs-comment"># 测试集的测试反馈</span>
                                        <span class="hljs-comment"># 为偏置权值插入常数项</span>
        X = np.insert(X, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, axis=<span class="hljs-number">1</span>)  <span class="hljs-comment"># 增加一个维度</span>
        y_pred = X.dot(self.w)          <span class="hljs-comment"># 测试集与拟合的训练集相乘</span>
        <span class="hljs-keyword">return</span> y_pred                   <span class="hljs-comment"># 返回最终的预测值</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">mean_squared_error</span><span class="hljs-params">(y_true, y_pred)</span>:</span>
                                        <span class="hljs-comment">#真实数据与预测数据之间的差值（平方平均）</span>
    mse = np.mean(np.power(y_true - y_pred, <span class="hljs-number">2</span>))
    <span class="hljs-keyword">return</span> mse

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-comment"># 第一步：导入数据</span>
    <span class="hljs-comment"># 加载糖尿病数据集</span>
    diabetes = datasets.load_diabetes()
    <span class="hljs-comment"># 只使用其中一个特征值(把一个422x10的矩阵提取其中一列变成422x1)</span>
    X = diabetes.data[:, np.newaxis, <span class="hljs-number">2</span>]  <span class="hljs-comment"># np.newaxis的作用就是在原来的数组上增加一个维度。2表示提取第三列数据</span>
    <span class="hljs-keyword">print</span> (X.shape)

    <span class="hljs-comment"># 第二步：将数据分为训练集以及测试集</span>
    x_train, x_test = X[:<span class="hljs-number">-20</span>], X[<span class="hljs-number">-20</span>:]
    print(x_train.shape,x_test.shape)  <span class="hljs-comment"># (422, 1) (20, 1)</span>
    <span class="hljs-comment"># 将目标分为训练/测试集合</span>
    y_train, y_test = diabetes.target[:<span class="hljs-number">-20</span>], diabetes.target[<span class="hljs-number">-20</span>:]
    print(y_train.shape,y_test.shape)  <span class="hljs-comment"># (422,) (20,)</span>

    <span class="hljs-comment">#第三步：导入线性回归类（之前定义的）</span>
    clf = LinearRegression()
    clf.fit(x_train, y_train)    <span class="hljs-comment"># 训练</span>
    y_pred = clf.predict(x_test) <span class="hljs-comment"># 测试</span>

    <span class="hljs-comment">#第四步：测试误差计算（需要引入一个函数）</span>
    <span class="hljs-comment"># 打印平均值平方误差</span>
    <span class="hljs-keyword">print</span> (<span class="hljs-string">"Mean Squared Error:"</span>, mean_squared_error(y_test, y_pred))  <span class="hljs-comment"># Mean Squared Error: 2548.072398725972</span>

    <span class="hljs-comment">#matplotlib可视化输出</span>
    <span class="hljs-comment"># Plot the results</span>
    plt.scatter(x_test[:,<span class="hljs-number">0</span>], y_test,  color=<span class="hljs-string">'black'</span>)         <span class="hljs-comment"># 散点输出</span>
    plt.plot(x_test[:,<span class="hljs-number">0</span>], y_pred, color=<span class="hljs-string">'blue'</span>, linewidth=<span class="hljs-number">3</span>) <span class="hljs-comment"># 预测输出</span>
    plt.show()

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    main()</code></pre></div>



            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">机器学习</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">机器学习</a>
                    
                      <a class="hover-with-bg" href="/tags/%E7%BA%BF%E6%80%A7%E5%9B%9E%E5%BD%92/">线性回归</a>
                    
                      <a class="hover-with-bg" href="/tags/python/">python</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://zh.wikipedia.org/wiki/Wikipedia:CC_BY-SA_3.0%E5%8D%8F%E8%AE%AE%E6%96%87%E6%9C%AC" target="_blank" rel="nofollow noopener noopener">CC BY-SA 3.0协议</a> 。转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2018/07/22/2018-07-21-ml-linearRegressionL1L2/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">机器学习-线性回归推导总结</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2018/07/20/2018-07-20-ml-linearRegression/">
                        <span class="hidden-mobile">机器学习之线性回归</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
              <!-- Comments -->
              <div class="comments" id="comments">
                
                
  <script defer src="https://utteranc.es/client.js"
          repo="sevenold/blog_comments"
          issue-term="pathname"
  
          label="utterances"
    
          theme="github-dark"
          crossorigin="anonymous"
  >
  </script>


              </div>
            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://ai-club.gitee.io" target="_blank" rel="nofollow noopener"><span>Seven</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://ai-club.gitee.io" target="_blank" rel="nofollow noopener"><span>算法</span></a>
    </div>
    
  <div>
    
      <!-- 不蒜子统计PV -->
      
      <span id="busuanzi_container_site_pv" style="display: none">
      总访问量 <span id="busuanzi_value_site_pv"></span> 次
    </span>
    
    
      <!-- 不蒜子统计UV -->
      
      <span id="busuanzi_container_site_uv" style="display: none">
      总访客数 <span id="busuanzi_value_site_uv"></span> 人
    </span>
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/main.js" ></script>


  <script  src="/js/lazyload.js" ></script>



  
  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '.post-content',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>





  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




<!-- Plugins -->


  
    <!-- Baidu Analytics -->
    <script defer>
      var _hmt = _hmt || [];
      (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?148e1083cf73cfd11f7ffaae0cd55877";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
  

  

  

  

  

  



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "机器学习之线性回归python实现&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>





  

  
    <!-- MathJax -->
    <script>
      MathJax = {
        tex: {
          inlineMath: [['$', '$'], ['\\(', '\\)']]
        },
        options: {
          renderActions: {
            findScript: [10, doc => {
              document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
                const display = !!node.type.match(/; *mode=display/);
                const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
                const text = document.createTextNode('');
                node.parentNode.replaceChild(text, node);
                math.start = { node: text, delim: '', n: 0 };
                math.end = { node: text, delim: '', n: 0 };
                doc.math.push(math);
              });
            }, '', false],
            insertedScript: [200, () => {
              document.querySelectorAll('mjx-container').forEach(node => {
                let target = node.parentNode;
                if (target.nodeName.toLowerCase() === 'li') {
                  target.parentNode.classList.add('has-jax');
                }
              });
            }, '', false]
          }
        }
      };
    </script>

    <script async src="https://cdn.staticfile.org/mathjax/3.0.5/es5/tex-svg.js" ></script>

  














</body>
</html>
